package vn.lumi.smarthome.network;

public class CreateSchedule extends AppMsg{

	//attributes
	private int Schedule_id=0;
	private int Device_id = 0;
	private boolean Repeat = false;
	private boolean[] Day = new boolean[7]; //7 days of a week Day[0] --> Monday
	private int[] StartTime = new int[2]; //[0] = hour, [1] =minute
	private int[] DeviceState = null;
	
	public CreateSchedule(int uid, int sid, int schedule_id, int dev_id, boolean repeat, boolean[] days, int[] start_time, int[] dev_state) {
		super(Message.CMD_APP_CREATE_SCHEDULE, uid, sid);
		Device_id = dev_id;
		Schedule_id = schedule_id;
		Repeat = repeat;
		Day = days;
		StartTime = start_time;
		DeviceState = dev_state;		
		// TODO Auto-generated constructor stub
	}

	@Override
	public byte[] generateByteArray() {
		// TODO Auto-generated method stub
		byte[] result = new byte[8 + DeviceState.length];
		result[0] = (byte) this.Cmd_id;
		result[1] = (byte) this.user_id;
		result[2] = (byte) this.session_id;
		result[3] = (byte) this.Schedule_id;
		result[4] = (byte) Device_id;
		//days
		for(int i = 0; i<7;i++){
			if(Day[i] == true)	result[5] |= (1<<(6-i));
			else result[5] &= ~(1<<(6-i));
		}
		if(Repeat == true)	result[5] |= (1<<7);
		else result[5] &= ~(1<<7);
		result[6] = (byte) StartTime[0];
		result[7] = (byte) StartTime[1];
		int stateLength = DeviceState.length;
		for(int i = 0; i< stateLength; i++){
			result[8+i] = (byte)DeviceState[i];
		}
		return result;
	}

}
